package com.fzy.modules.bill.service;

import com.fzy.core.common.IDUtils;
import com.fzy.core.common.PageObject;
import com.fzy.modules.bill.dao.WsBillDao;
import com.fzy.modules.bill.entity.SoBillDetail;
import com.fzy.modules.bill.entity.WsBill;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 出库单操作
 */
@Service
public class WsBillService {
    @Autowired
    WsBillDao wsBillDao;
    /**
     * 添加出库单
     */
    public Integer save(WsBill wsBill){
        wsBill.setId(IDUtils.genItemId());
        wsBill.setBizdt(new Date());
        wsBill.setDateCreated(new Date());
        return wsBillDao.addWsBill(wsBill);
    }
    /**
     * 查询出库单
     */
    public PageObject<WsBill> findWsBillList(WsBill wsBill, int page, int rows){
        PageHelper.startPage(page, rows);
        List<WsBill> sobills = wsBillDao.findWsBillList(wsBill);
        //查询之后获取分页对象
        PageInfo<WsBill> pageInfo=new PageInfo<WsBill>(sobills);
        //构建我们自定义的分页实体返回类
        PageObject<WsBill> pageObject=new PageObject<WsBill>();
        pageObject.setTotal(pageInfo.getTotal());
        pageObject.setRows(sobills);
        return pageObject;
    }
    /**
     * 查询所有未出库单号
     */
    public List<WsBill> findWsBill(){
        WsBill wsBill=new WsBill();
        wsBill.setBillStatus(0);
        return wsBillDao.findWsBillList(wsBill);
    }
}
